import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

App.mpType = 'app'

Vue.prototype.$getSystemInfo = function() {
	return new Promise((resolve, reject) => {
		uni.getSystemInfo({
			success(info) {
				resolve(info)
			},
			fail(err) {
				reject(err)
			}
		})
	})
};

Vue.prototype.$postRequst = function(url, data) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: this.$urlPrefix + url,
			method: "POST",
			data: data,
			success(info) {
				resolve(info)
			},
			fail(err) {
				reject(err)
			}
		})
	})
}

Vue.prototype.$myonce = function(para) {
	return new Promise((resolve, reject) => {
		uni.$once(para, function(data) {
			resolve(data)
		})
	})
}

Vue.prototype.$fixGoods = function(goods) {
	for (var i = 0; i < goods.length; i++) {	//将json文件重新构建为js对象
		goods[i].packages = JSON.parse(goods[i].packageJson)
	}
	return goods
}

Vue.prototype.$fixOneGoods = function(goods) {
	goods.packages = JSON.parse(goods.packageJson)
	return goods
}

Vue.prototype.$screenHeight = 667;
Vue.prototype.$screenWidth = 375;

Vue.prototype.$request = function(url, data, func){
	uni.request({
		url: this.$urlPrefix + url,
		data: data,
		method: "POST",
		success(res) {
			//console.log(res);
			func(res)
		},
		fail(err) {
			console.log("请求出错！");
			console.log(err);
			uni.hideLoading()
		}
	})
}

Vue.prototype.$user = uni.getStorageSync("user")

Vue.prototype.$getNowUser = function(){
	return uni.getStorageSync("user")
}

Vue.prototype.$setNowUser = function(user){
	uni.setStorageSync("user",user)
}

Vue.prototype.$urlPrefix = "http://localhost:8081/"
const app = new Vue({
	...App
})
app.$mount()

/* 
	限制text显示行数css代码:
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	text-overflow: ellipsis;
	overflow: hidden;
	display: -webkit-box;
 */